home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / MacODBC / ODBC Tools / SampleApp / LibraryManager.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-16  |  41.9 KB  |  1,475 lines  |  [TEXT/MPS ]

  1. /*    File:        LibraryManager.h
  2.  
  3.     Contains:    Minimal declarations you need to use the ASLM.
  4.  
  5.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  6.  
  7.  
  8. */
  9.  
  10. #ifndef __LIBRARYMANAGER__
  11. #define __LIBRARYMANAGER__
  12.  
  13. #if defined(powerpc) || defined(__powerpc)
  14.     #define ASLM_COMPATIBLE    /* */
  15.     #define MAC68K                0
  16.     #define VOLATILE            volatile
  17.     #define SINGLEOBJECT        0
  18.     #define MPWC
  19.     #ifndef __CONDITIONALMACROS__
  20.         #ifndef SystemSevenOrLater
  21.         #define SystemSevenOrLater        1
  22.         #endif
  23.         #ifndef USES68KINLINES
  24.         #define USES68KINLINES            0
  25.         #endif
  26.         #ifndef USESROUTINEDESCRIPTORS
  27.         #define USESROUTINEDESCRIPTORS    1
  28.         #endif
  29.         #ifndef USESCODEFRAGMENTS
  30.         #define USESCODEFRAGMENTS        1
  31.         #endif
  32.     #endif
  33. #else
  34.     #define MAC68K                1
  35.     #if defined(__SC__)
  36.         #if !NoDummyVTableSlot
  37.             #define ASLM_COMPATIBLE                                \
  38.                 private:                                        \
  39.                     virtual        void DummyVirtualFunction();
  40.                     
  41.             #define ASLM_SCDECLARATION(className)        \
  42.             void className::DummyVirtualFunction() {}
  43.         #else
  44.             #define ASLM_COMPATIBLE        /* */
  45.             #define ASLM_SCDECLARATION    /* */
  46.         #endif
  47.         
  48.         #define VOLATILE        volatile
  49.         #define SINGLEOBJECT    0
  50.         #define MPWC            _cdecl
  51.     #else
  52.         #define ASLM_COMPATIBLE    /* */
  53.         #define VOLATILE
  54.         #define SINGLEOBJECT    1
  55.         #define MPWC
  56.     #endif
  57.     #ifndef __CONDITIONALMACROS__
  58.         #ifndef SystemSevenOrLater
  59.         #define SystemSevenOrLater        0
  60.         #endif
  61.         #ifndef USES68KINLINES
  62.         #define USES68KINLINES            1
  63.         #endif
  64.         #ifndef USESROUTINEDESCRIPTORS
  65.         #define USESROUTINEDESCRIPTORS    0
  66.         #endif
  67.         #ifndef USESCODEFRAGMENTS
  68.         #define USESCODEFRAGMENTS        0
  69.         #endif
  70.     #endif
  71. #endif
  72.  
  73. #ifndef OLDROUTINENAMES
  74. #define OLDROUTINENAMES 1
  75. #endif
  76.  
  77. #undef SystemSixOrLater
  78. #define SystemSixOrLater    1
  79.  
  80. #ifndef __STDDEF__
  81. #include <stddef.h>
  82. #endif
  83. #ifndef __STRING__
  84. #undef    NULL
  85. #include <String.h>
  86. #endif
  87.  
  88. //dm: must include Types.h even for SC: #define true/false breaks Types.h later on
  89. //#if !defined(__SC__)
  90.     #ifndef __TYPES__
  91.     #include <Types.h>
  92.     #endif
  93. //#endif
  94.  
  95. /*******************************************************************************
  96. ** Some Typedefs and constants
  97. ********************************************************************************/
  98.  
  99. #ifndef NULL
  100. #define NULL        0
  101. #endif
  102.  
  103. #ifndef __TYPES__
  104. typedef char*            Ptr;
  105. typedef short            OSErr;
  106. typedef long             (*ProcPtr)();
  107. typedef unsigned char    Boolean;
  108. typedef unsigned long    ResType;
  109. typedef unsigned char     Str63[64];
  110.  
  111. #define false    ((Boolean)0)
  112. #define true    ((Boolean)1)
  113. #endif
  114.  
  115. //
  116. //    The following are parameter typedefs to force Symantec compilers to pass
  117. //    one byte parameters as two byte parameters so you can call MPW built
  118. //    shared libraries from Symantec built clients.
  119. //
  120. #if MAC68K
  121.     typedef    int                OSErrParm;
  122.     typedef unsigned int    BooleanParm;
  123.     typedef int                charParm;
  124.     typedef unsigned int    ucharParm;
  125.     typedef int                shortParm;
  126.     typedef unsigned int    ushortParm;
  127.     typedef long double        floatParm;
  128.     typedef long double        doubleParm;
  129. #else
  130.     typedef    OSErr            OSErrParm;
  131.     typedef Boolean            BooleanParm;
  132.     typedef char            charParm;
  133.     typedef unsigned char    ucharParm;
  134.     typedef short            shortParm;
  135.     typedef unsigned short    ushortParm;
  136.     typedef float            floatParm;
  137.     typedef double            doubleParm;
  138. #endif
  139.  
  140. /*******************************************************************************
  141. ** Some external routines
  142. ********************************************************************************/
  143.  
  144. #ifdef __cplusplus
  145. extern "C" {
  146. #endif
  147.     char* strcpy(char* s1, const char* s2);
  148. #ifdef __cplusplus
  149. };
  150. #endif
  151.  
  152. /*******************************************************************************
  153. ** Error Constants
  154. ********************************************************************************/
  155.  
  156. #define kNoError                        0
  157. #define kNotFound                        -3120
  158. #define kNoParent                        -3121
  159. #define kParentNotFound                    -3122
  160. #define kNotRelated                        -3123
  161. #define kInvalidObject                    -3124
  162. #define kPoolCorrupted                    -3125
  163. #define kOutOfMemory                    -3126
  164. #define kCodeNotLoaded                    -3127
  165. #define kCouldNotLoadCode                -3128
  166. #define kFilePreflighted                -3129
  167. #define kFileNotPreflighted                -3130
  168. #define kFileNotFound                    -3131
  169. #define kLibraryManagerNotLoaded        -3132
  170. #define kDuplicateFound                    -3134
  171. #define kSeedChanged                    -3135
  172. #define kUnconstructedObject            -3136
  173. #define kInternalError                    -3137
  174. #define kVersionError                    -3138
  175. #define kFolderNotFound                    -3139
  176. #define kFolderInUse                    -3140
  177. #define kResourceNotFound                -3141
  178. #define kNotAllowedNow                    -3155
  179. #define kNotSupported                    -3167
  180.     
  181. #define kASLMNotFoundErr                -3120
  182. #define kASLMNoParentErr                -3121
  183. #define kASLMParentNotFoundErr            -3122
  184. #define kASLMNotRelatedErr                -3123
  185. #define kASLMInvalidObjectErr            -3124
  186. #define kASLMPoolCorruptedErr            -3125
  187. #define kASLMOutOfMemoryErr                -3126
  188. #define kASLMCodeNotLoadedErr            -3127
  189. #define kASLMCouldNotLoadCodeErr        -3128
  190. #define kASLMFilePreflightedErr            -3129
  191. #define kASLMFileNotPreflightedErr        -3130
  192. #define kASLMFileNotFoundErr            -3131
  193. #define kASLMLibraryManagerNotLoadedErr    -3132
  194. #define kASLMDuplicateFoundErr            -3134
  195. #define kASLMSeedChangedErr                -3135
  196. #define kASLMUnconstructedObjectErr        -3136
  197. #define kASLMInternalErr                -3137
  198. #define kASLMVersionErr                    -3138
  199. #define kASLMFolderNotFoundErr            -3139
  200. #define kASLMFolderInUseErr                -3140
  201. #define kASLMResourceNotFoundErr        -3141
  202. #define kASLMNotAllowedNowErr            -3155
  203. #define kASLMNotSupportedErr            -3167
  204.  
  205. /*******************************************************************************
  206. ** Typedefs
  207. ********************************************************************************/
  208.  
  209. typedef void*            GlobalWorld;
  210. #define kInvalidWorld    ((GlobalWorld)0)
  211.  
  212. typedef unsigned short    Version;
  213. #define kAnyVersion        ((Version)0)
  214.  
  215. #define    TFunctionSetID    TClassID
  216. #define    TLibraryID        TClassID
  217. #define    FunctionSetID    ClassID        /* for casting a cstring to a TFunctionSetID */
  218. #define    LibraryID        ClassID        /* for casting a cstring to a TLibraryID */
  219.  
  220. /*******************************************************************************
  221. ** Forward class declarations
  222. ********************************************************************************/
  223.  
  224. #ifdef __cplusplus
  225.     class    TDynamic;
  226.     class    TLibraryManager;
  227.     class    TClassID;
  228.     class    TFunctionSetID;
  229.     class    TLibraryID;
  230.     class    TLibrary;
  231.     class    TFormattedStream;
  232.     class    TMemoryPool;
  233.     class    TStandardPool;
  234.     class    TLibraryFile;
  235.     class     TClassInfo;
  236.     class    TException;
  237.     class    TSimpleList;
  238.     class    TFileSpec;
  239. #else
  240.     typedef char* TClassID;
  241.     typedef void TDynamic;
  242.     typedef void TLibraryManager;
  243.     typedef void TFormattedStream;
  244.     typedef void TStandardPool;
  245.     typedef void TClassInfo;
  246.     typedef void TLibrary;
  247.     typedef void TMemoryPool;
  248. #endif
  249.  
  250.  
  251. /*******************************************************************************
  252. ** Memory definitions
  253. ********************************************************************************/
  254.  
  255. typedef int    ZoneType;
  256.  
  257. #define kSystemZone                ((ZoneType)1)
  258. #define kKernelZone                ((ZoneType)2)
  259. #define kApplicZone                ((ZoneType)3)
  260. #define kCurrentZone            ((ZoneType)4)
  261. #define kTempZone                ((ZoneType)5)
  262.  
  263. typedef int    MemoryType;
  264.  
  265. #define kNormalMemory            ((MemoryType)1)
  266. #define kHoldMemory                ((MemoryType)2)
  267. #define kLockMemory                ((MemoryType)3)
  268. #define kLockMemoryContiguous    ((MemoryType)4)
  269.  
  270. /*******************************************************************************
  271. ** STACKOBJECTONLY: Use in a class declaration so the object can only be created
  272. ** on the stack. This makes the constructors and destructors much smaller since
  273. ** they know they will never have to new or delete memory.
  274. ********************************************************************************/
  275.  
  276. #define STACKOBJECTONLY                                                \
  277.     private:                                                        \
  278.                 void*    operator new(size_t) { return NULL; }        \
  279.                 void    operator delete(void*) {}
  280.  
  281. /*******************************************************************************
  282. ** Some "C" Global routines
  283. **
  284. ** InitLibraryManager initializes a client to use the ASLM. All clients
  285. ** must make this call except for ASLM libraries. CleanupLibraryManager
  286. ** should be called when the client is done using the ASLM.
  287. **
  288. ** GetLocalLibraryManager can be called after InitLibraryManager is called. If it
  289. ** returns NULL then InitLibraryManager failed.
  290. ********************************************************************************/
  291.  
  292. #ifdef __cplusplus
  293.     extern "C" {
  294. #endif
  295.  
  296. /*    -------------------------------------------------------------------------
  297.     These functions are for use by applications or stand-alone code 
  298.     resources only
  299.     ------------------------------------------------------------------------- */
  300.  
  301. #ifdef __cplusplus
  302.         
  303. OSErr                InitLibraryManager(size_t poolsize = 0, ZoneType = kCurrentZone,
  304.                                        MemoryType = kNormalMemory);
  305. void                CleanupLibraryManager();
  306.     
  307. #else
  308.  
  309. OSErr                InitLibraryManager(size_t poolsize, int zoneType, int memType);
  310. void                CleanupLibraryManager(void);
  311.     
  312. #endif
  313.  
  314. /*    -------------------------------------------------------------------------
  315.     These functions can be used by any Shared Library Manager clients
  316.     ------------------------------------------------------------------------- */
  317.  
  318. #ifdef __cplusplus
  319.  
  320. Boolean                IsDerivedFrom(const void*, const TClassID&);
  321. const TClassID&        GetObjectsClassID(const void*);
  322. const TClassID&        GetObjectsParentClassID(const void*);
  323. size_t                GetObjectsSize(const void*);
  324. TLibrary*            GetObjectsLocalLibrary(const void*);
  325. TLibraryFile*        GetObjectsLocalLibraryFile(const void*);
  326. TStandardPool*        GetObjectsLocalPool(const void*);
  327. void                SetObjectsLocalPool(const void*, TStandardPool*);
  328.  
  329. void*                NewObject(const TClassID&, OSErr* = NULL,
  330.                               TStandardPool* = NULL);
  331. void*                NewObjectWithParent(const TClassID&,
  332.                                         const TClassID& parentID,
  333.                                         OSErr* = NULL, TStandardPool* = NULL);
  334. void*                NewObjectFromStream(const TFormattedStream&,
  335.                                         OSErr* = NULL, TStandardPool* = NULL);
  336.  
  337. TClassInfo*         GetClassInfo(const TClassID&, OSErr* = NULL);
  338.  
  339. OSErr                VerifyClass(const TClassID&, const TClassID& parentID);
  340. void*                CastObject(const void*, const TClassID& parentID, OSErr* = NULL);
  341. void*                CastToMainObject(const void*);
  342.  
  343. OSErr                LoadClass(const TClassID&, BooleanParm forceAll);
  344. OSErr                UnloadClass(const TClassID&);
  345. Boolean                IsClassLoaded(const TClassID&);
  346.  
  347. OSErr                LoadFunctionSet(const TFunctionSetID&, BooleanParm forceAll);
  348. OSErr                UnloadFunctionSet(const TFunctionSetID&);
  349. Boolean                IsFunctionSetLoaded(const TFunctionSetID&);
  350.  
  351. ProcPtr                GetFunctionPointer(const TFunctionSetID&, const char* funcName,
  352.                                        OSErr* = NULL);
  353. ProcPtr                GetIndexedFunctionPointer(const TFunctionSetID&, unsigned int index,
  354.                                               OSErr* = NULL);
  355.  
  356. OSErr                LoadLibraries(BooleanParm forceAll = true,
  357.                                   BooleanParm doSelf = true);
  358. OSErr                UnloadLibraries();
  359. void                ResetFunctionSet(const TFunctionSetID* = NULL);
  360.         
  361. Boolean                TraceLogOn();
  362. Boolean                TraceLogOff();
  363.  
  364. void                RegisterDynamicObject(TDynamic*);
  365. void                UnregisterDynamicObject(TDynamic*);
  366.     
  367. TLibraryManager*    GetLocalLibraryManager();
  368.     
  369. TStandardPool*        GetLocalPool();
  370. void                SetLocalPool(TStandardPool*);
  371. TStandardPool*        GetClientPool();
  372. TStandardPool*        GetDefaultPool();
  373. void                SetDefaultPool(TStandardPool*);
  374. TStandardPool*        GetSystemPool();
  375.     
  376. #else
  377.     
  378. void*                NewObject(const TClassID, OSErr*, TStandardPool*);
  379. void*                NewObjectWithParent(const TClassID, const TClassID parentID,
  380.                                         OSErr*, TStandardPool*);
  381. void*                NewObjectFromStream(const TFormattedStream*, OSErr*,
  382.                                         TStandardPool*);
  383.  
  384. TClassInfo*         GetClassInfo(const TClassID, OSErr*);
  385.  
  386. OSErr                VerifyClass(const TClassID, const TClassID parentID);
  387. void*                CastObject(const void*, const TClassID parentID, OSErr*);
  388. void*                CastToMainObject(const void*);
  389.  
  390. OSErr                LoadClass(const TClassID, BooleanParm forceAll);
  391. OSErr                UnloadClass(const TClassID);
  392. Boolean                IsClassLoaded(const TClassID);
  393.  
  394. OSErr                LoadFunctionSet(const TFunctionSetID, BooleanParm forceAll);
  395. OSErr                UnloadFunctionSet(const TFunctionSetID);
  396. Boolean                IsFunctionSetLoaded(const TFunctionSetID);
  397.  
  398. ProcPtr                GetFunctionPointer(const TFunctionSetID, const char* funcName,
  399.                                        OSErr*);
  400. ProcPtr                GetIndexedFunctionPointer(const TFunctionSetID, unsigned int index,
  401.                                               OSErr*);
  402.  
  403. OSErr                LoadLibraries(BooleanParm forceAll, BooleanParm doSelf);
  404. OSErr                UnloadLibraries(void);
  405. void                ResetFunctionSet(const TFunctionSetID);
  406.         
  407. Boolean                TraceLogOn();
  408. Boolean                TraceLogOff();
  409.  
  410. TLibraryManager*    GetLocalLibraryManager(void);
  411.  
  412. TStandardPool*        GetLocalPool();
  413. void                SetLocalPool(TStandardPool*);
  414. TStandardPool*        GetClientPool();
  415. TStandardPool*        GetDefaultPool();
  416. void                SetDefaultPool(TStandardPool*);
  417. TStandardPool*        GetSystemPool();
  418.  
  419. #endif
  420.  
  421. /*    -------------------------------------------------------------------------
  422.     These functions are only used for their inline value.
  423.     Do not call them directly.
  424.     ------------------------------------------------------------------------- */
  425.  
  426. #ifdef __cplusplus
  427.     extern void* SLMNewOperator(size_t, TMemoryPool*);
  428.     extern void SLMDeleteOperator(void*);
  429. }
  430.  
  431. /*******************************************************************************
  432. ** CLASS TSimpleDynamic
  433. **
  434. ** A base class for shared-library classes that has no virtual functions.  This
  435. ** class is NOT shared, since it is intended to be a trivial class that just
  436. ** forces the VTable to be at the front of the object.
  437. ********************************************************************************/
  438.  
  439. #if SINGLEOBJECT
  440. class TSimpleDynamic : public SingleObject
  441. #else
  442. class TSimpleDynamic
  443. #endif
  444. {
  445.     ASLM_COMPATIBLE
  446.  
  447.     public:
  448.         virtual                  ~ MPWC TSimpleDynamic();
  449.         
  450.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  451.                                     { return SLMNewOperator(size, pool); }
  452.                 void*            operator new(size_t size)                        // from default pool
  453.                                     { return SLMNewOperator(size, 0); }
  454.                 void            operator delete(void* obj, size_t)
  455.                                     { SLMDeleteOperator(obj); }
  456.  
  457.                 const TClassID&    MPWC GetObjectsClassID() const;
  458.                 const TClassID&    MPWC GetObjectsParentClassID() const;
  459.                 size_t            MPWC GetObjectsSize() const;
  460.                 TLibrary*        MPWC GetObjectsLocalLibrary() const;
  461.                 TLibraryFile*    MPWC GetObjectsLocalLibraryFile() const;
  462.                 TStandardPool*    MPWC GetObjectsLocalPool() const;
  463.                 void            MPWC SetObjectsLocalPool(TStandardPool*) const;
  464.     
  465.                 Boolean            MPWC IsDerivedFrom(const TClassID&) const;
  466.                 
  467.     protected:
  468.                                   MPWC TSimpleDynamic();
  469.  
  470.     private:
  471.                                 TSimpleDynamic(const TSimpleDynamic&);
  472.                 void            operator=(const TSimpleDynamic&);
  473. };
  474.  
  475. /*******************************************************************************
  476. ** CLASS TDynamic
  477. **
  478. ** The base class for shared-library classes with a set of common capabilities.
  479. ** This class provides the same capabilities as TStdDynamic.
  480. ********************************************************************************/
  481.  
  482. typedef int    TraceControlType;
  483.  
  484. #define kTraceStatus    ((TraceControlType)1)
  485. #define kTraceOn        ((TraceControlType)2)
  486. #define kTraceOff        ((TraceControlType)3)
  487.  
  488. #define kTDynamicID "!$dyna,1.1"
  489.  
  490. #if SINGLEOBJECT
  491. class TDynamic : public SingleObject
  492. #else
  493. class TDynamic
  494. #endif
  495. {
  496.     ASLM_COMPATIBLE
  497.  
  498.     public:
  499.         virtual                  ~ MPWC TDynamic();
  500.         
  501.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  502.                                     { return SLMNewOperator(size, pool); }
  503.                 void*            operator new(size_t size)                        // from default pool
  504.                                     { return SLMNewOperator(size, 0); }
  505.                 void            operator delete(void* obj, size_t)
  506.                                     { SLMDeleteOperator(obj); }
  507.                                     
  508.  
  509.         const TClassID&            MPWC GetObjectsClassID() const;
  510.         const TClassID&            MPWC GetObjectsParentClassID() const;
  511.                 size_t            MPWC GetObjectsSize() const;
  512.                 TLibrary*        MPWC GetObjectsLocalLibrary() const;
  513.                 TLibraryFile*    MPWC GetObjectsLocalLibraryFile() const;
  514.                 TStandardPool*    MPWC GetObjectsLocalPool() const;
  515.                 void            MPWC SetObjectsLocalPool(TStandardPool*) const;
  516.  
  517.         virtual Boolean            MPWC IsValid() const;
  518.         
  519.         virtual    OSErr            MPWC Inflate(TFormattedStream&);
  520.         virtual OSErr            MPWC Flatten(TFormattedStream&) const;
  521.         virtual TDynamic*        MPWC Clone(TStandardPool*) const;
  522.         
  523.         virtual    char*            MPWC GetVerboseName(char*) const;
  524.         virtual    void            MPWC Dump() const;
  525.         
  526.                 void            MPWC Trace(char *formatStr, ...) const;
  527.         virtual    Boolean            MPWC TraceControl(TraceControlType) const;
  528.                 Boolean            MPWC IsTraceOn() const;    
  529.                 Boolean            MPWC TraceOn() const;
  530.                 Boolean            MPWC TraceOff() const;
  531.     
  532.                 Boolean            MPWC IsDerivedFrom(const TClassID&) const;
  533.                 
  534.     protected:
  535.                                   MPWC TDynamic();
  536.  
  537.     private:
  538.                                 TDynamic(const TDynamic&);
  539.                 void            operator=(const TDynamic&);
  540. };
  541.  
  542. /*    -------------------------------------------------------------------------
  543.     Inline methods for TDynamic
  544.     ------------------------------------------------------------------------- */
  545.  
  546.     inline Boolean TDynamic::IsTraceOn() const
  547.     {
  548.         return TraceControl(kTraceStatus);
  549.     }
  550.  
  551.     inline Boolean TDynamic::TraceOn() const
  552.     {
  553.         return TraceControl(kTraceOn);
  554.     }
  555.  
  556.     inline Boolean TDynamic::TraceOff() const
  557.     {
  558.         return TraceControl(kTraceOff);
  559.     }
  560.  
  561. /*******************************************************************************
  562. ** CLASS MDynamic
  563. **
  564. ** A base class for shared-library classes, which has one 1 virtual function (the
  565. ** destructor).  This class is NOT shared, since it is intended to be a trivial class
  566. ** that can be used to force the VTable to be at the front of the object for
  567. ** mixin classes.
  568. ********************************************************************************/
  569.  
  570. class MDynamic
  571. {
  572.     ASLM_COMPATIBLE
  573.  
  574.     public:
  575.         virtual                  ~MDynamic();
  576.         
  577.     protected:
  578.                                   MDynamic();
  579.  
  580.     private:
  581.                                 MDynamic(const MDynamic&);
  582.                 void            operator=(const MDynamic&);
  583. };
  584.  
  585. /*******************************************************************************
  586. ** CLASS TStdDynamic
  587. **
  588. ** The base class for shared-library classes with a set of common capabilities.
  589. ** This class provides the same capabilities as TDynamic below, but is for
  590. ** classes that you don't want to descend from SingleObject.
  591. ********************************************************************************/
  592.  
  593. #define kTStdDynamicID "!$sdyn,1.1"
  594.  
  595. class TStdDynamic
  596. {
  597.     ASLM_COMPATIBLE
  598.  
  599.     public:
  600.         virtual                  ~ MPWC TStdDynamic();
  601.         
  602.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  603.                                     { return SLMNewOperator(size, pool); }
  604.                 void*            operator new(size_t size)                        // from default pool
  605.                                     { return SLMNewOperator(size, 0); }
  606.                 void            operator delete(void* obj, size_t)
  607.                                     { SLMDeleteOperator(obj); }
  608.                                     
  609.  
  610.         const TClassID&            MPWC GetObjectsClassID() const;
  611.                 size_t            MPWC GetObjectsSize() const;
  612.                 TLibrary*        MPWC GetObjectsLocalLibrary() const;
  613.                 TLibraryFile*    MPWC GetObjectsLocalLibraryFile() const;
  614.                 TStandardPool*    MPWC GetObjectsLocalPool() const;
  615.                 void            MPWC SetObjectsLocalPool(TStandardPool*) const;
  616.  
  617.         virtual Boolean            MPWC IsValid() const;
  618.         
  619.         virtual    OSErr            MPWC Inflate(TFormattedStream&);
  620.         virtual OSErr            MPWC Flatten(TFormattedStream&) const;
  621.         virtual TDynamic*        MPWC Clone(TStandardPool*) const;
  622.         
  623.         virtual    char*            MPWC GetVerboseName(char*) const;
  624.         virtual    void            MPWC Dump() const;
  625.         
  626.                 void            MPWC Trace(char *formatStr, ...) const;
  627.         virtual    Boolean            MPWC TraceControl(TraceControlType) const;
  628.                 Boolean            IsTraceOn() const;    
  629.                 Boolean            TraceOn() const;
  630.                 Boolean            TraceOff() const;
  631.     
  632.                 Boolean            MPWC IsDerivedFrom(const TClassID&) const;
  633.                 
  634.     protected:
  635.                                   MPWC TStdDynamic();
  636.  
  637.     private:
  638.                                 TStdDynamic(const TDynamic&);
  639.                 void            operator=(const TDynamic&);
  640. };
  641.  
  642. /*    -------------------------------------------------------------------------
  643.     Inline methods for TStdDynamic
  644.     ------------------------------------------------------------------------- */
  645.  
  646.     inline Boolean TStdDynamic::IsTraceOn() const
  647.     {
  648.         return TraceControl(kTraceStatus);
  649.     }
  650.  
  651.     inline Boolean TStdDynamic::TraceOn() const
  652.     {
  653.         return TraceControl(kTraceOn);
  654.     }
  655.  
  656.     inline Boolean TStdDynamic::TraceOff() const
  657.     {
  658.         return TraceControl(kTraceOff);
  659.     }
  660.  
  661. /*******************************************************************************
  662. ** CLASS TStdSimpleDynamic
  663. **
  664. ** A base class for shared-library classes that has no virtual functions.  This
  665. ** class is NOT shared, since it is intended to be a trivial class that just
  666. ** forces the VTable to be at the front of the object.
  667. ********************************************************************************/
  668.  
  669. class TStdSimpleDynamic
  670. {
  671.     ASLM_COMPATIBLE
  672.  
  673.     public:
  674.         virtual                  ~ MPWC TStdSimpleDynamic();
  675.         
  676.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  677.                                     { return SLMNewOperator(size, pool); }
  678.                 void*            operator new(size_t size)                        // from default pool
  679.                                     { return SLMNewOperator(size, 0); }
  680.                 void            operator delete(void* obj, size_t)
  681.                                     { SLMDeleteOperator(obj); }
  682.  
  683.                 const TClassID&    MPWC GetObjectsClassID() const;
  684.                 size_t            MPWC GetObjectsSize() const;
  685.                 TLibrary*        MPWC GetObjectsLocalLibrary() const;
  686.                 TLibraryFile*    MPWC GetObjectsLocalLibraryFile() const;
  687.                 TStandardPool*    MPWC GetObjectsLocalPool() const;
  688.                 void            MPWC SetObjectsLocalPool(TStandardPool*) const;
  689.     
  690.                 Boolean            MPWC IsDerivedFrom(const TClassID&) const;
  691.                 
  692.     protected:
  693.                                   MPWC TStdSimpleDynamic();
  694.  
  695.     private:
  696.                                 TStdSimpleDynamic(const TStdSimpleDynamic&);
  697.                 void            operator=(const TStdSimpleDynamic&);
  698. };
  699.  
  700. #ifdef __SC__
  701.  
  702. /*******************************************************************************
  703. ** CLASS TSCSimpleDynamic
  704. **
  705. ** A base class for shared-library classes that has no virtual functions.  This
  706. ** class is NOT shared, since it is intended to be a trivial class that just
  707. ** forces the VTable to be at the front of the object, and override new to
  708. ** use the ASLM operators. It is used as a simple base class for Symantec C++ objects.
  709. ** This is the normal subclass for Symantec C++ objects that are not going to 
  710. ** intermix with MPW C++ objects.
  711. ********************************************************************************/
  712.  
  713. class TSCSimpleDynamic
  714. {
  715.     ASLM_COMPATIBLE
  716.  
  717.     public:
  718.         virtual                  ~TSCSimpleDynamic();
  719.         
  720.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  721.                                     { return SLMNewOperator(size, pool); }
  722.                 void*            operator new(size_t size)                        // from default pool
  723.                                     { return SLMNewOperator(size, 0); }
  724.                 void            operator delete(void* obj, size_t)
  725.                                     { SLMDeleteOperator(obj); }
  726.  
  727.                 const TClassID&    GetObjectsClassID() const;
  728.                 const TClassID&    GetObjectsParentClassID() const;
  729.                 size_t            GetObjectsSize() const;
  730.                 TLibrary*        GetObjectsLocalLibrary() const;
  731.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  732.                 TStandardPool*    GetObjectsLocalPool() const;
  733.                 void            SetObjectsLocalPool(TStandardPool*) const;
  734.     
  735.                 Boolean            IsDerivedFrom(const TClassID&) const;
  736.                 
  737.     protected:
  738.                                   TSCSimpleDynamic();
  739.  
  740.     private:
  741.                                 TSCSimpleDynamic(const TSCSimpleDynamic&);
  742.                 void            operator=(const TSCSimpleDynamic&);
  743. };
  744.  
  745. /*******************************************************************************
  746. ** CLASS TSCDynamic
  747. **
  748. ** The base class for shared-library classes with a set of common capabilities.
  749. ** This class provides the same capabilities as TStdDynamic.  It is only for
  750. ** Symantec C++ implementations
  751. ********************************************************************************/
  752.  
  753. #define kTSCDynamicID "!$scdy,1.1"
  754.  
  755. class TSCDynamic
  756. {
  757.     ASLM_COMPATIBLE
  758.  
  759.     public:
  760.         virtual                  ~ _cdecl TSCDynamic();
  761.         
  762.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  763.                                     { return SLMNewOperator(size, pool); }
  764.                 void*            operator new(size_t size)                        // from default pool
  765.                                     { return SLMNewOperator(size, 0); }
  766.                 void            operator delete(void* obj, size_t)
  767.                                     { SLMDeleteOperator(obj); }
  768.                                     
  769.         const TClassID&            GetObjectsClassID() const;
  770.         const TClassID&            GetObjectsParentClassID() const;
  771.                 size_t            GetObjectsSize() const;
  772.                 TLibrary*        GetObjectsLocalLibrary() const;
  773.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  774.                 TStandardPool*    GetObjectsLocalPool() const;
  775.                 void            SetObjectsLocalPool(TStandardPool*) const;
  776.  
  777.         virtual Boolean            _cdecl IsValid() const;
  778.         
  779.         virtual    OSErr            _cdecl Inflate(TFormattedStream&);
  780.         virtual OSErr            _cdecl Flatten(TFormattedStream&) const;
  781.         virtual TSCDynamic*        _cdecl Clone(TStandardPool*) const;
  782.         
  783.         virtual    char*            _cdecl GetVerboseName(char*) const;
  784.         virtual    void            _cdecl Dump() const;
  785.         
  786.                 void            Trace(char *formatStr, ...) const;
  787.         virtual    Boolean            _cdecl TraceControl(TraceControlType) const;
  788.                 Boolean            IsTraceOn() const;    
  789.                 Boolean            TraceOn() const;
  790.                 Boolean            TraceOff() const;
  791.     
  792.                 Boolean            IsDerivedFrom(const TClassID&) const;
  793.                 
  794.     protected:
  795.                                   _cdecl TSCDynamic();
  796.  
  797.     private:
  798.                                 TSCDynamic(const TSCDynamic&);
  799.                 void            operator=(const TSCDynamic&);
  800. };
  801.  
  802. /*    -------------------------------------------------------------------------
  803.     Inline methods for TSCDynamic
  804.     ------------------------------------------------------------------------- */
  805.  
  806.     inline Boolean TSCDynamic::IsTraceOn() const
  807.     {
  808.         return TraceControl(kTraceStatus);
  809.     }
  810.  
  811.     inline Boolean TSCDynamic::TraceOn() const
  812.     {
  813.         return TraceControl(kTraceOn);
  814.     }
  815.  
  816.     inline Boolean TSCDynamic::TraceOff() const
  817.     {
  818.         return TraceControl(kTraceOff);
  819.     }
  820.     
  821. #endif    /* __SC__ */
  822. #endif    /* __cplusplus */
  823.  
  824. /*******************************************************************************
  825. ** Class TClassID, TFunctionSetID, and TLibraryID
  826. **
  827. ** TFunctionSetID and TLibraryID are typedef'd to be the same as TClassID
  828. ********************************************************************************/
  829.  
  830. #define kMaxClassIDSize        255
  831.  
  832. #ifdef __cplusplus
  833.  
  834. const TClassID& ClassID(const char* str);    // cast a char* to a TClassID
  835.  
  836. Boolean operator==(const TClassID&, const char *);
  837. Boolean operator!=(const TClassID&, const char *);
  838. Boolean operator==(const char *, const TClassID&);
  839. Boolean operator!=(const char *, const TClassID&);
  840.  
  841. class TClassID
  842. {
  843.     public:
  844.         void*        operator new(size_t, size_t strLen, TMemoryPool* thePool = NULL)
  845.                     {
  846.                         return SLMNewOperator(strLen+1, thePool);
  847.                     }
  848.  
  849.         void*        operator new(size_t)
  850.                     {
  851.                         return SLMNewOperator(kMaxClassIDSize+1, NULL);
  852.                     }
  853.                         
  854.         void        operator delete(void* obj, size_t)
  855.                         { SLMDeleteOperator(obj); }
  856.  
  857.                     TClassID();
  858.                     TClassID(const TClassID&);
  859.  
  860.                     operator const char*() const;        // cast to a const char *
  861.  
  862.         Version        MPWC ExtractVersion() const;
  863.         size_t        MPWC GetLength() const;
  864.         
  865.         TClassID&    operator=(const TClassID&);
  866.  
  867.         Boolean        operator==(const TClassID&) const;
  868.         Boolean        operator!=(const TClassID&) const;
  869.  
  870.     private:
  871.         char                fClassIDStr[kMaxClassIDSize + 1];
  872. };
  873.  
  874. /*    -------------------------------------------------------------------------
  875.     Inline methods for TClassID
  876.     ------------------------------------------------------------------------- */
  877.  
  878.     //
  879.     // constructors
  880.     //
  881.  
  882.     inline TClassID::TClassID()
  883.     {
  884.         fClassIDStr[0] = 0;
  885.     }
  886.     
  887.     inline TClassID::TClassID(const TClassID& classID)
  888.     {
  889.         strcpy(fClassIDStr, classID.fClassIDStr);
  890.     }
  891.  
  892.     //
  893.     // cast operators
  894.     //
  895.  
  896.     inline const TClassID& ClassID(const char* str)
  897.     {
  898.         return *(const TClassID*)str;
  899.     }
  900.     
  901.     inline TClassID::operator const char *() const
  902.     {
  903.         return fClassIDStr;
  904.     }
  905.  
  906.     //
  907.     // compare operators
  908.     //
  909.     
  910.     inline Boolean TClassID::operator!=(const TClassID& classID) const
  911.     {
  912.         return !(*this == classID);
  913.     }
  914.     
  915.     inline Boolean operator!=(const TClassID& id1, const char *id2)
  916.     {
  917.         return !(id1 == ClassID(id2));
  918.     }
  919.  
  920.     inline Boolean operator!=(const char *id1, const TClassID& id2)
  921.     {
  922.         return !(id2 == ClassID(id1));
  923.     }
  924.     
  925.     inline Boolean operator==(const TClassID& id1, const char *id2)
  926.     {
  927.         return (id1 == ClassID(id2));
  928.     }
  929.     
  930.     inline Boolean operator==(const char *id1, const TClassID& id2)
  931.     {
  932.         return (id2 == ClassID(id1));
  933.     }
  934.  
  935.     //
  936.     // assignment operators
  937.     //
  938.     
  939.     inline TClassID& TClassID::operator=(const TClassID& classID)
  940.     {
  941.         strcpy(fClassIDStr, classID.fClassIDStr);
  942.         return *this;
  943.     }
  944.     
  945. #endif
  946.  
  947. /*******************************************************************************
  948. ** Class TLibraryManager
  949. **
  950. ** The user's interface to the world! 
  951. ********************************************************************************/
  952.  
  953. #ifdef __cplusplus
  954.  
  955. #define kTLibraryManagerID "!$lmgr,1.1"
  956.  
  957. class TLibraryManager : public TDynamic 
  958. {
  959.  
  960.     private:
  961.         virtual                    ~ MPWC TLibraryManager();
  962.                                 MPWC TLibraryManager(TStandardPool* = NULL, TLibraryFile* = NULL);
  963.  
  964.     public:
  965.         virtual    void            MPWC Dump() const;
  966.  
  967.         // New Methods
  968.         
  969.         virtual    void*            MPWC NewObject(const TClassID& classID,
  970.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  971.         virtual    void*            MPWC NewObject(const TClassID& classID, const TClassID& baseClassID,
  972.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  973.         virtual    void*            MPWC NewObject(const TFormattedStream&,
  974.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  975.  
  976.         virtual TClassInfo*     MPWC GetClassInfo(const TClassID&, OSErr* = NULL) const;
  977.  
  978.         virtual OSErr            MPWC VerifyClass(const TClassID& classID, const TClassID& baseClassID) const;
  979.         virtual void*            MPWC CastObject(const void* obj, const TClassID& parentID,
  980.                                                 OSErr* = NULL) const;
  981.         virtual void*            MPWC CastToMainObject(const void* obj) const;
  982.         
  983.         virtual OSErr            MPWC LoadClass(const TClassID&, BooleanParm loadAll = false);
  984.         virtual OSErr            MPWC UnloadClass(const TClassID&);
  985.         virtual Boolean            MPWC IsClassLoaded(const TClassID&) const;
  986.  
  987.                 OSErr            LoadFunctionSet(const TFunctionSetID&, BooleanParm loadAll = false);
  988.                 OSErr            UnloadFunctionSet(const TFunctionSetID&);
  989.                 Boolean            IsFunctionSetLoaded(const TFunctionSetID&) const;
  990.         
  991.         virtual ProcPtr            MPWC GetFunctionPointer(const TFunctionSetID&,
  992.                                                    const char* funcName,
  993.                                                    OSErr* = NULL);
  994.         virtual ProcPtr            MPWC GetFunctionPointer(const TFunctionSetID&,
  995.                                                    unsigned int index,
  996.                                                    OSErr* = NULL);
  997.         
  998.         virtual OSErr            MPWC LoadLibraries(BooleanParm forceAll = true,
  999.                                                    BooleanParm doSelf = true);
  1000.         virtual OSErr            MPWC UnloadLibraries();
  1001.         virtual void            MPWC ResetFunctionSet(const TFunctionSetID* = NULL);
  1002.         
  1003.         virtual Boolean            MPWC TraceLogOn();
  1004.         virtual Boolean            MPWC TraceLogOff();
  1005.         
  1006.         virtual    void            MPWC RegisterDynamicObject(TDynamic*);
  1007.         virtual    void            MPWC UnregisterDynamicObject(TDynamic*);
  1008.  
  1009.                 void            SetObjectPool(TStandardPool*);
  1010.                 TStandardPool*    GetObjectPool() const;
  1011.                 void            SetDefaultPool(TStandardPool*);
  1012.                 TStandardPool*    GetDefaultPool() const;
  1013.                 GlobalWorld        MPWC GetGlobalWorld() const;
  1014.         virtual    TLibrary*        MPWC GetLibrary() const;
  1015.         virtual    TLibraryFile*    MPWC GetLibraryFile() const;
  1016.  
  1017.     private:
  1018.                                 TLibraryManager(const TLibraryManager&);
  1019.                 void            operator=(const TLibraryManager&);
  1020.     private:        
  1021.         TStandardPool*            fPool;            // pool used for new objects and local pool
  1022.         TLibraryFile*            fLibraryFile;
  1023.         TStandardPool*            fDefaultPool;
  1024.         GlobalWorld                fGlobalWorld;
  1025.  
  1026. };
  1027.  
  1028. /*    -------------------------------------------------------------------------
  1029.     Inline Methods for TLibraryManager
  1030.     ------------------------------------------------------------------------- */
  1031.     
  1032.     inline OSErr TLibraryManager::LoadFunctionSet(const TFunctionSetID& functionSetID, BooleanParm loadAll)
  1033.     {
  1034.         return LoadClass(functionSetID, loadAll);
  1035.     }
  1036.     
  1037.     inline OSErr TLibraryManager::UnloadFunctionSet(const TFunctionSetID& functionSetID)
  1038.     {
  1039.         return UnloadClass(functionSetID);
  1040.     }
  1041.     
  1042.     inline Boolean TLibraryManager::IsFunctionSetLoaded(const TFunctionSetID& functionSetID) const
  1043.     {
  1044.         return IsClassLoaded(functionSetID);
  1045.     }
  1046.     
  1047.     inline TStandardPool* TLibraryManager::GetObjectPool() const
  1048.     {
  1049.         return fPool;
  1050.     }
  1051.     
  1052.     inline void TLibraryManager::SetObjectPool(TStandardPool* thePool)
  1053.     {
  1054.         fPool = thePool;
  1055.     }
  1056.         
  1057.     inline TStandardPool* TLibraryManager::GetDefaultPool() const
  1058.     {
  1059.         return fDefaultPool;
  1060.     }
  1061.  
  1062.     inline void TLibraryManager::SetDefaultPool(TStandardPool* thePool)
  1063.     {
  1064.         fDefaultPool = thePool;
  1065.     }
  1066.     
  1067.     inline GlobalWorld TLibraryManager::GetGlobalWorld() const
  1068.     {
  1069.         return fGlobalWorld;
  1070.     }
  1071.  
  1072. /*    -------------------------------------------------------------------------
  1073.     Inline for IsDerivedFrom
  1074.     ------------------------------------------------------------------------- */
  1075.  
  1076.     inline Boolean IsDerivedFrom(const void* obj, const TClassID& id)
  1077.     {
  1078.         return (GetLocalLibraryManager()->CastObject(obj, id) != NULL);
  1079.     }
  1080.  
  1081. /*    -------------------------------------------------------------------------
  1082.     Inline methods for TDynamic
  1083.     ------------------------------------------------------------------------- */
  1084.  
  1085.     inline Boolean TDynamic::IsDerivedFrom(const TClassID& id) const
  1086.     {
  1087.         return ::IsDerivedFrom(this, id);
  1088.     }
  1089.  
  1090.     inline const TClassID& TDynamic::GetObjectsClassID() const
  1091.     {
  1092.         return ::GetObjectsClassID(this);
  1093.     }
  1094.  
  1095.     inline const TClassID& TDynamic::GetObjectsParentClassID() const
  1096.     {
  1097.         return ::GetObjectsParentClassID(this);
  1098.     }
  1099.  
  1100.     inline size_t TDynamic::GetObjectsSize() const
  1101.     {
  1102.         return ::GetObjectsSize(this);
  1103.     }
  1104.  
  1105.     inline TLibrary* TDynamic::GetObjectsLocalLibrary() const
  1106.     {
  1107.         return ::GetObjectsLocalLibrary(this);
  1108.     }
  1109.  
  1110.     inline TLibraryFile* TDynamic::GetObjectsLocalLibraryFile() const
  1111.     {
  1112.         return ::GetObjectsLocalLibraryFile(this);
  1113.     }
  1114.  
  1115.     inline TStandardPool* TDynamic::GetObjectsLocalPool() const
  1116.     {
  1117.         return ::GetObjectsLocalPool(this);
  1118.     }
  1119.  
  1120.     inline void TDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1121.     {
  1122.         ::SetObjectsLocalPool(this, pool);
  1123.     }
  1124.     
  1125. /*    -------------------------------------------------------------------------
  1126.     Inline methods for TSimpleDynamic
  1127.     ------------------------------------------------------------------------- */
  1128.  
  1129.     inline const TClassID& TSimpleDynamic::GetObjectsClassID() const
  1130.     {
  1131.         return ((const TDynamic*)this)->GetObjectsClassID();
  1132.     }
  1133.  
  1134.     inline const TClassID& TSimpleDynamic::GetObjectsParentClassID() const
  1135.     {
  1136.         return ((const TDynamic*)this)->GetObjectsParentClassID();
  1137.     }
  1138.  
  1139.     inline size_t TSimpleDynamic::GetObjectsSize() const
  1140.     {
  1141.         return ((const TDynamic*)this)->GetObjectsSize();
  1142.     }
  1143.  
  1144.     inline TLibrary* TSimpleDynamic::GetObjectsLocalLibrary() const
  1145.     {
  1146.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1147.     }
  1148.  
  1149.     inline TLibraryFile* TSimpleDynamic::GetObjectsLocalLibraryFile() const
  1150.     {
  1151.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1152.     }
  1153.  
  1154.     inline TStandardPool* TSimpleDynamic::GetObjectsLocalPool() const
  1155.     {
  1156.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1157.     }
  1158.  
  1159.     inline void TSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1160.     {
  1161.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1162.     }
  1163.  
  1164.     inline Boolean TSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1165.     {
  1166.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1167.     }
  1168.     
  1169. /*    -------------------------------------------------------------------------
  1170.     Inline methods for TStdDynamic
  1171.     ------------------------------------------------------------------------- */
  1172.  
  1173.     inline const TClassID& TStdDynamic::GetObjectsClassID() const
  1174.     {
  1175.         return ((const TDynamic*)this)->GetObjectsClassID();
  1176.     }
  1177.  
  1178.     inline size_t TStdDynamic::GetObjectsSize() const
  1179.     {
  1180.         return ((const TDynamic*)this)->GetObjectsSize();
  1181.     }
  1182.  
  1183.     inline TLibrary* TStdDynamic::GetObjectsLocalLibrary() const
  1184.     {
  1185.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1186.     }
  1187.  
  1188.     inline TLibraryFile* TStdDynamic::GetObjectsLocalLibraryFile() const
  1189.     {
  1190.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1191.     }
  1192.  
  1193.     inline TStandardPool* TStdDynamic::GetObjectsLocalPool() const
  1194.     {
  1195.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1196.     }
  1197.  
  1198.     inline void TStdDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1199.     {
  1200.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1201.     }
  1202.     
  1203.     inline Boolean TStdDynamic::IsDerivedFrom(const TClassID& id) const
  1204.     {
  1205.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1206.     }
  1207.  
  1208. /*    -------------------------------------------------------------------------
  1209.     Inline methods for TStdSimpleDynamic
  1210.     ------------------------------------------------------------------------- */
  1211.  
  1212.     inline const TClassID& TStdSimpleDynamic::GetObjectsClassID() const
  1213.     {
  1214.         return ((const TDynamic*)this)->GetObjectsClassID();
  1215.     }
  1216.  
  1217.     inline size_t TStdSimpleDynamic::GetObjectsSize() const
  1218.     {
  1219.         return ((const TDynamic*)this)->GetObjectsSize();
  1220.     }
  1221.  
  1222.     inline TLibrary* TStdSimpleDynamic::GetObjectsLocalLibrary() const
  1223.     {
  1224.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1225.     }
  1226.  
  1227.     inline TLibraryFile* TStdSimpleDynamic::GetObjectsLocalLibraryFile() const
  1228.     {
  1229.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1230.     }
  1231.  
  1232.     inline TStandardPool* TStdSimpleDynamic::GetObjectsLocalPool() const
  1233.     {
  1234.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1235.     }
  1236.  
  1237.     inline void TStdSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1238.     {
  1239.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1240.     }
  1241.     
  1242.     inline Boolean TStdSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1243.     {
  1244.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1245.     }
  1246.     
  1247. #ifdef __SC__
  1248.  
  1249. /*    -------------------------------------------------------------------------
  1250.     Inline methods for TSCDynamic
  1251.     ------------------------------------------------------------------------- */
  1252.  
  1253.     inline Boolean TSCDynamic::IsDerivedFrom(const TClassID& id) const
  1254.     {
  1255.         return ::IsDerivedFrom(this, id);
  1256.     }
  1257.  
  1258.     inline const TClassID& TSCDynamic::GetObjectsClassID() const
  1259.     {
  1260.         return ::GetObjectsClassID(this);
  1261.     }
  1262.  
  1263.     inline const TClassID& TSCDynamic::GetObjectsParentClassID() const
  1264.     {
  1265.         return ::GetObjectsParentClassID(this);
  1266.     }
  1267.  
  1268.     inline size_t TSCDynamic::GetObjectsSize() const
  1269.     {
  1270.         return ::GetObjectsSize(this);
  1271.     }
  1272.  
  1273.     inline TLibrary* TSCDynamic::GetObjectsLocalLibrary() const
  1274.     {
  1275.         return ::GetObjectsLocalLibrary(this);
  1276.     }
  1277.  
  1278.     inline TLibraryFile* TSCDynamic::GetObjectsLocalLibraryFile() const
  1279.     {
  1280.         return ::GetObjectsLocalLibraryFile(this);
  1281.     }
  1282.  
  1283.     inline TStandardPool* TSCDynamic::GetObjectsLocalPool() const
  1284.     {
  1285.         return ::GetObjectsLocalPool(this);
  1286.     }
  1287.  
  1288.     inline void TSCDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1289.     {
  1290.         ::SetObjectsLocalPool(this, pool);
  1291.     }
  1292.     
  1293. /*    -------------------------------------------------------------------------
  1294.     Inline methods for TSCSimpleDynamic
  1295.     ------------------------------------------------------------------------- */
  1296.  
  1297.     inline const TClassID& TSCSimpleDynamic::GetObjectsClassID() const
  1298.     {
  1299.         return ((const TSCDynamic*)this)->GetObjectsClassID();
  1300.     }
  1301.  
  1302.     inline const TClassID& TSCSimpleDynamic::GetObjectsParentClassID() const
  1303.     {
  1304.         return ((const TSCDynamic*)this)->GetObjectsParentClassID();
  1305.     }
  1306.  
  1307.     inline size_t TSCSimpleDynamic::GetObjectsSize() const
  1308.     {
  1309.         return ((const TSCDynamic*)this)->GetObjectsSize();
  1310.     }
  1311.  
  1312.     inline TLibrary* TSCSimpleDynamic::GetObjectsLocalLibrary() const
  1313.     {
  1314.         return ((const TSCDynamic*)this)->GetObjectsLocalLibrary();
  1315.     }
  1316.  
  1317.     inline TLibraryFile* TSCSimpleDynamic::GetObjectsLocalLibraryFile() const
  1318.     {
  1319.         return ((const TSCDynamic*)this)->GetObjectsLocalLibraryFile();
  1320.     }
  1321.  
  1322.     inline TStandardPool* TSCSimpleDynamic::GetObjectsLocalPool() const
  1323.     {
  1324.         return ((const TSCSimpleDynamic*)this)->GetObjectsLocalPool();
  1325.     }
  1326.  
  1327.     inline void TSCSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1328.     {
  1329.         ((const TSCSimpleDynamic*)this)->SetObjectsLocalPool(pool);
  1330.     }
  1331.  
  1332.     inline Boolean TSCSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1333.     {
  1334.         return ((const TSCSimpleDynamic*)this)->IsDerivedFrom(id);
  1335.     }
  1336.     
  1337. #endif        /* __SC__ */
  1338. #endif        /* __cplusplus */
  1339.  
  1340. /*******************************************************************************
  1341. ** EXCEPTION Handling
  1342. **
  1343. ** Some RULES:
  1344. ** 1) Never propogate a failure outside of a constructor or destructor.
  1345. **    If your constructor or destructor can call something which fails, it
  1346. **    _must_ CATCH the failure and not re-propogate it.
  1347. ** 2) Never create an object inside of a "try" block which you cannot 
  1348. **    destroy (especially an auto object).
  1349. ** 3) if you are going to just RERAISE the exception, or Fail 
  1350. **      with a different error, you must manually call the destructors 
  1351. **    of any  auto objects that are still in scope!
  1352. ** 4) Any variables that are changed inside the "try", and which are tested
  1353. **    inside a CATCH, CATCH_ALL, or FINALLY must be declared "volatile" 
  1354. **      (Use the Volatile macro below until C++ and volatile work!)
  1355. ** 5) Never call Fail while an auto variable is in scope - it's 
  1356. **      destructor will not be called unless you call it manually.
  1357. ** 6) FINALLY is always entered after TRY unless a CATCH clause raises
  1358. **    (or re-raises) an exception (this is true even if an exception was
  1359. **    not thrown).
  1360. ********************************************************************************/
  1361.  
  1362. struct TException
  1363. {
  1364.     struct TException*    fPrev;
  1365.     size_t                fReserved;
  1366.     long                fBuffer[12];
  1367.     char*                fMessage;
  1368.     void*                fPtr;
  1369.     OSErr                fError;
  1370. };
  1371.  
  1372. #ifdef __cplusplus
  1373. extern "C" {
  1374. #else
  1375. typedef struct TException    TException;
  1376. #endif
  1377.  
  1378. void        MPWC PushException(TException*);
  1379. TException*    MPWC PopException(TException*);
  1380. Boolean        MPWC MatchException(TException*, long);
  1381.  
  1382. #if USES68KINLINES
  1383. #pragma parameter __D0 SetupException(__A0)
  1384. int SetupException(long* val) =
  1385. {
  1386.     0x43fa, 0x0008,    /* lea        *+10,a1 */
  1387.     0x48d0, 0xdefc,    /* movem.l    d2-d7/a1-a4/a6/a7,(a0) */
  1388.     0x7000            /* moveq    #0,d0 */
  1389. };
  1390. #else
  1391. int SetupException(long* val);
  1392. #endif
  1393.  
  1394. #ifdef __cplusplus
  1395. }
  1396. #endif
  1397.     
  1398. /*    -----------------------------------------------------------------
  1399.     Some important functions for exception handling
  1400.     ----------------------------------------------------------------- */
  1401.  
  1402. #ifdef __cplusplus
  1403. extern "C" {
  1404. void MPWC Fail(long err, const char* msg=NULL);
  1405. }
  1406. #else
  1407. void MPWC Fail(long err, const char* msg);
  1408. #endif
  1409.  
  1410. #ifdef __cplusplus
  1411. inline void FailNULL(void* val, long err, const char* msg=NULL) 
  1412.     if (val == 0) 
  1413.         Fail(err, msg); 
  1414. }
  1415. #else
  1416. #define FailNULL(val, err, msg)        \
  1417.     if (val == 0) { Fail(err, msg); } else {}
  1418. #endif
  1419.  
  1420. #if qDebug
  1421. #define DebugFail(err, msg)                Fail(err, msg)
  1422. #define DebugFailNULL(ptr, err, msg)    FailNULL(ptr, err, msg)
  1423. #else
  1424. #define DebugFail(err, msg)                Fail(err, NULL)
  1425. #define DebugFailNULL(ptr, err, msg)    FailNULL(ptr, err, NULL)
  1426. #endif
  1427.  
  1428.  
  1429. #define ErrorCode()                 (except.fError)
  1430. #define ErrorMessage()                (except.fMessage)
  1431. #define Volatile(x)                    ((void) &x)
  1432.  
  1433. /*    -----------------------------------------------------------------
  1434.     The RAISE/RERAISE/TRY/CATCH/CATCH_ALL/FINALLY/ENDTRY macros
  1435.     ----------------------------------------------------------------- */
  1436.  
  1437. #define RAISE(x)     Fail(x,NULL)
  1438.  
  1439. #define TRY                                                 \
  1440.     {                                                        \
  1441.         TException    except;                                    \
  1442.         Volatile(except);                                    \
  1443.         PushException(&except);                                \
  1444.         if (SetupException(except.fBuffer) == 0)            \
  1445.         {
  1446.         
  1447. #define CATCH(e)                                            \
  1448.         }                                                    \
  1449.         else if (MatchException(&except, e))                \
  1450.         { 
  1451.         
  1452.         
  1453. #define CATCH_ALL                                            \
  1454.         }                                                    \
  1455.         else                                                \
  1456.         { 
  1457.         
  1458.         
  1459. #define RERAISE                                                \
  1460.         Fail(ErrorCode(), ErrorMessage())
  1461.         
  1462. #define FINALLY                                                \
  1463.         }                                                    \
  1464.         PopException(&except);                                \
  1465.         if (ErrorCode() != kNoError) RERAISE;                \
  1466.         {
  1467.         
  1468. #define ENDTRY                                                \
  1469.         }                                                    \
  1470.         PopException(&except);                                \
  1471.     }
  1472.  
  1473. #endif
  1474.